﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Web.Mvc;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Models;
using Prodma.DataAccess.Helper.Enumerators;

namespace Prodma.DataAccess.DataService.ListService
{
    public class SurveyList
    {
        private static DataContext context = new DataContext();

        public static SelectList GetList()
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from area in context.tb_Survey
                            where area.tb_State.Id == stateId
                            select area);
                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value");

                return selectList;
            }
        }
        public static SelectList GetList(int id)
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from area in context.tb_Survey
                            where area.tb_State.Id == stateId
                            select area);
                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value", id);

                return selectList;
            }
        }

        public static MultiSelectList GetSelectedOptionList(int surveyId)
        {
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from option in context.tb_SurveyOption
                            where option.tb_Survey.Id == surveyId
                            select option);

                MultiSelectList multiList = new MultiSelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value");
                return multiList;
            }
        }
    }
}
